package ui.swing.event;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRootPane;

public class PostEvent {
	public static void main(String[] args) {
		//JFrame.setDefaultLookAndFeelDecorated(true);
		final JFrame jf = new JFrame();
		jf.setSize(100, 200);
		
		jf.setUndecorated(true);
		jf.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
		Dimension d = jf.getToolkit().getScreenSize();
		jf.setLocation(d.width/2 - jf.getWidth()/2, d.height/2 - jf.getHeight()/2);
		
		JButton btn = new JButton("postOneKeyEvent!");
		btn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				KeyEvent evt = new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), 0, 0, '\n');
				EventQueue eq = jf.getToolkit().getSystemEventQueue();
				eq.postEvent(evt);
			}
		});
		jf.getContentPane().add(btn);
		btn.addKeyListener(new MyKeyListener());

		jf.setVisible(true);
	}
	
	static class MyKeyListener implements KeyListener {

		public void keyPressed(KeyEvent e) {
			System.out.println("keyPressed");
			System.out.println(e);
		}

		public void keyReleased(KeyEvent e) {
			System.out.println("keyReleased");
			System.out.println(e);
		}

		public void keyTyped(KeyEvent e) {
			System.out.println("keyTyped");
			System.out.println(e);
		}
		
	}
}
